Networking and Communications

Texto Justificado

Group assignment:

  • Send a message between two projects.
  • Document your work to the group work page and reflect on your individual page what you learned.

Individual assignments

  • design, build and connect wired or wireless node(s) with network or bus addresses and a local interface.

Group Assignment

  • Here is the link where you can see the development of the week's group assignment.Group Assignment

Imagen

Shared use to turn on an actuator

In this step it is crucial to activate sharing within your account, as interaction will be required. An invitation was made to another person, in my case a colleague from Fabacademy

Imagen


Imagen

Configure the Thins and here you see the code

Once sharing is enabled, we proceed to create the dashboard, device and thing on the Arduino IoT Cloud platform and then configure them according to our needs.

Imagen


Imagen

Upload the code and make the dashboard work

Once the interaction is configured and created, which can include anything from an LED to actuators, the next step is to configure the WiFi credentials, password and security key. Subsequently, we proceed to load the program into the XIAO ESP32 with the desired interaction

Imagen


Imagen

Video of how the group task works




In summary

A key lesson I learned in this activity was the importance of making sure the Arduino Cloud virtual agent is installed correctly. I did not initially notice this detail, as the program loading seemed successful, but the final installation did not complete. I later discovered that I had completely skipped installing the necessary agent. Once I installed the agent correctly, everything ran smoothly and was ready to test.



Individual assignment

For my individual assignment this week, I used the XIAO ESP32-C3 along with the WiFi communication protocol. This choice allowed me to move forward on our final project while taking advantage of the capabilities of this device.

Connection via Wi-Fi communication protocol

To use the XIAO ESP32-C3 with Arduino to connect to the Arduino IoT Cloud via Wi-Fi, follow these steps to configure and program your device:


Imagen

Step 1: Hardware Preparation

XIAO ESP32-C3 Board:

  • Make sure you have a XIAO ESP32-C3 board compatible with the Arduino development environment.

USB connection:

  • Connect the XIAO ESP32-C3 board to your computer using a USB-C cable.

Step 2: Arduino IoT Cloud Setup

Registration in Arduino IoT Cloud:

  • Register in Arduino IoT Cloud (cloud.arduino.cc) and create a new project.

Imagen


Imagen

Add Devices to Project:

  • Add your XIAO ESP32 C3 board to the project from the IoT Cloud interface.
Imagen


Imagen

Imagen

In setup we choose the correct board.


Imagen

Now we select the correct device.

Imagen

Naming the project.


Imagen

Downloading project credentials.

  • From the "Sketch" tab, click "Add Device."
  • Select your device and click "Next."
  • Select the properties you want to include in your code (be sure to select the property you just created to control the LED).
Imagen

.


Imagen

.


Imagen

.


Imagen

.


Imagen

.


Imagen

.


Step 3: Generate the Code in Arduino IoT Cloud

Implement the code necessary for your Arduino to communicate with the Arduino IoT Cloud. This includes configuring project parameters and reading/sending data to/from connected devices.


Imagen

.


Imagen

.


Imagen

.


Imagen

.


Imagen

.


Imagen

.


Step 4: Modify the Code to Control the LED

Set the LED Pin:


  • In the generated code, identify the pin your LED is connected to on the XIAO ESP32-C3 board. For example.

                                const int ledPin = 2; // Example: LED connected to pin 13
                                

Implement the Logic to Control the LED:

  • Inside the loop() of the code, read the state of the "LEDControl" property from the Arduino IoT Cloud and use this state to turn the LED on or off. For example:

                                void loop() {
                                    ArduinoCloud.update();
                                
                                    // Control del LED
                                    if (LEDControl) {
                                    digitalWrite(ledPin, HIGH); // on LED
                                    } else {
                                    digitalWrite(ledPin, LOW); // off LED
                                    }
                                }
                            

Code


Step 5: Upload the Code to your Device

Connect your Device and Upload the Code:

  • Connect your XIAO ESP32-C3 board to your computer.
  • Select the correct board and port on the Arduino IDE.
  • Upload the modified code to your device.

Imagen

.


Imagen

.


Step 6: Control the LED from the Dashboard

Access the Arduino IoT Cloud Dashboard:

  • Go to the "Dashboard" section in Arduino IoT Cloud.

Add a Widget to Control the LED:

  • Click "Add Widget" and select the appropriate widget to control the "LEDControl" property.
  • Configure the widget so that it can turn the LED on and off.

Imagen

.


Imagen

.



Wifi communication through IOT Cloud Arduino of an Actuator and Turbidity sensor

As part of my project, I implemented a system to measure water turbidity and conducted tests using three different types of water. This process allowed me to analyze and compare turbidity in different samples, thus contributing to the objectives and results of my research.



Imagen


Once the account has been created, the next step in this process is to configure another device to be able to read the turbidity sensor data. In addition, it is required to implement the functionality to control the on and off of a solenoid valve. This stage will allow the integration of turbidity measurement capabilities with the control of the water treatment system, which is essential for the successful development of this project

Imagen

.


Imagen

.


After that, we proceed to configure which sensors and outputs we want to display on the control panel (Dashboard). In addition, we select the appropriate device to integrate with the Dashboard and configure the WiFi network name, the network password and finally the security key (key) necessary for the connection. This configuration phase will allow us to customize and optimize the display of data in the Dashboard, ensuring a fluid and secure integration of our system with the network and the selected devices.


Imagen

.


Imagen

.


In the next step, we proceed to enter the integrated development environment (IDE) or Sketch, where we will write the code that will be loaded into the XIAO. To access this environment, we click on option number 2 called 'editor', which will take us to the workspace necessary to program and configure the XIAO ESP32 device.


Code

Imagen

.


Imagen

.


After this, we add our code and proceed to load it on our XIAO ESP32 device

Imagen

.


Imagen

.


As a result of the values ​​obtained, we can view the data from the turbidity sensor and control an actuator (such as a 220V pump) to activate or deactivate it.


Imagen

.






I2C communication between two boards

I2C (Inter-Integrated Circuit) communication is a synchronous serial communication protocol used to connect electronic devices to each other on a printed circuit board or through short cables. It was developed by Philips Semiconductor (now NXP Semiconductors) in the 1980s and has become a de facto standard for communication between microcontrollers, sensors, actuators, memories and other peripheral devices.

Características principales de I2C:

Two lines of communication:

  • SDA (Serial Data Line): Bidirectional serial data line through which data is transmitted between devices.
  • SCL (Serial Clock Line): Clock line that synchronizes the data transfer speed between connected devices.

Bus topology:

  • It allows connecting multiple devices (up to 128 unique addresses) on the same communication bus, using only two cables for data transmission.

Master-slave protocol:

  • In a typical configuration, one of the devices acts as a master (controls communication) and the others act as slaves (respond to requests from the master).

Data transfer:

  • I2C communication allows data to be transferred serially using packets of bytes, with a structure that includes device addresses, commands, and specific data to control and transmit information between devices.

Transmission speed:

  • It can operate at different speeds, typically 100 kHz (standard mode), 400 kHz (fast mode), and in some cases up to 3.4 MHz (fast plus mode), depending on the capabilities of the connected devices.

Configuration of the Xiao ESP32-S3:

Configure one of the Xiao ESP32-S3 as a master (sender) and the other as a slave (receiver) for I2C communication. You must assign unique addresses for each device in I2C communication.

Programming the Arduino as an Emitter:

Program your Arduino to send a numerical value through the serial port. For example, send the character '1' to turn the LED on the receiver on and '0' to turn it off.

Programming the Xiao ESP32-S3 as a Receiver:

On the Xiao ESP32-S3 receiver, program it to read the data received by I2C from the Arduino through the serial port. Depending on the value received ('1' or '0'), it turns the corresponding LED on or off.

Implementation of I2C Communication:

Use the appropriate functions and libraries on both Xiao ESP32-S3 to establish I2C communication. You can use the Wire library that is standard in Arduino and adapted for the ESP32.

LED control:

Implement the logic in the Xiao ESP32-S3 receiver so that, upon receiving the correct value via I2C, it turns the connected LED on or off.


Issuer code



Receiver Code



For communication I used, as I mentioned in the theory, a sender or master and a receiver or slave. For this, I used two XIAO ESP32-S3. On the receiver, I connected an LED to GPIO 2, which is activated by sending characters from the sender: a '1' to turn the LED on and a '0' to turn it off. All this is controlled from the emitter

Imagen

Issuer


Imagen

Receiver

For my tests I used jumpers and a breadboard due to lack of time, as I needed to quickly test this type of communication. However, seeing what this communication protocol does, I will take the time necessary to design and manufacture their respective boards.

Imagen

The following video shows the communication protocol implemented using two XIAO ESP32-S3. In the demonstration, the sender sends commands to control an LED connected to GPIO 2 of the receiver. I used jumpers and a breadboard for initial testing due to time constraints.



In summary

This week has been very productive, since I learned to establish communication between the XIAO ESP32 C3 and the WiFi, which has allowed me to control an actuator, in this case a solenoid valve, from a web platform. In addition, I was also able to turn this solenoid valve on and off from my cell phone, using the Arduino IOT cloud platform. I'm excited about the many applications and projects I can explore, such as integrating functionality with ALEXA and other applications.

However, not everything was so fast and fluid. I encountered some difficulties, such as the fact that some public institutions, such as the university where I work, impose certificates on their WiFi networks, which limits our total control over them. At first, I thought the problem was in my code, but after reviewing it thoroughly, I realized that everything was correct. To test it, I shared the connection from my cell phone as an access point and it worked without problems. This allowed me to confirm that everything was fine, and I was then able to test it on other WiFi networks in my house, where everything worked correctly.

Links to all working files used this week

1. Turbidity sensor test.ino
2. Receiver.ino
3. Transmitter.ino